<?php
require_once 'config.php';
//require_once 'tabelaEmolumentoTabeliaes';

if (isset($_POST['enviar'])) {

	$query = "SELECT emolumento FROM tabeliaes WHERE escritura IN (SELECT min(escritura) FROM tabeliaes WHERE escritura>=$_POST[escritura])";
	$result = mysql_query($query);

	while ($row = mysql_fetch_array($result)) {

		echo "Valor: ".$row['emolumento'];
	}

	echo "<hr />";

}else;


?>

<form name="tabeliaesForm" action="" method="post">
	<fieldset>
		<label>
			<span>Calcular escritura:</span><br />
			<input type="text" name="escritura" value="">
		</label>
		<br />
		<input type="submit" name="enviar" value="Calcular">
	</fieldset>
</form>

<?php

//require_once 'config.php';

$sql = "SELECT escritura, emolumento FROM tabeliaes";
$consulta = mysql_query($sql);

echo "<table border='1'>";
	echo "<tr>";
		echo "<td width='150'>Escritura</td>";
		echo "<td width='150'>Emolumento</td>";
	echo "</tr>";
echo "</table>";

while ($registro = mysql_fetch_assoc($consulta)) {
	echo "<table border='1'>";
		echo "<tr>";
			echo "<td width='150'>".$registro["escritura"];
			echo "<td width='150'>".$registro["emolumento"];
		echo "</tr>";
	echo "</table>";
}

//echo "</table>";


?>